<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>项目列表</title>
    <?php PrintPageHead(); ?>
    <link href="../resource/css/hermes.css" rel="stylesheet">
    <link href="../resource/js/calendar/calendar-blue.css" type="text/css" rel="stylesheet">
    <script src="../resource/js/calendar/calendar.js" type="text/javascript"></script>
    <script src="../resource/js/hermes.js"></script>

    <?php
    if (!array_key_exists("公众号ID",$_SESSION)) {
        header("Location:back.php");
    }
    $bm=new C后台管理员();
    $参数=array();
    $sql ="SELECT a.*,b.`name` ,(SELECT COUNT(*) FROM `语音课程报名` c WHERE c.`课程id` = a.id and c.`状态` = '报名') AS `数量` FROM `语音课程` a LEFT JOIN `用户` b ON (a.`讲课专家id` = b.id) WHERE a.`type`='视频' ORDER BY a.id DESC ";
    $r显示2 =$bm->f通过sql分页($sql,@$_GET['page'],$_GET);
    $添加视频课程 = 'back.php?state=back8Shipin_Lessons';
    ?>
</head>
<body>


<div class="container-fluid">
    <?php include_once 'back_header.php'; ?>
    <div class="panel panel-primary">
        <div class="panel-heading text-center"><h3 class="panel-title">管理视频课程</h3></div>
        <div class="panel-group"  id="accordion" role="tablist" aria-multiselectable="true">
            <div class="panel-heading text-right"><a href="<?=$添加视频课程?>" type="button" class="btn btn-primary">添加视频课程</a></div>
            <div class="panel-heading text-right">
                测试openID: <input type="text" id="oid">
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="row" >

                        <div class="col-xs-1 col-sm-1" style="text-align:center">
                            主题
                        </div>
                        <div class="col-xs-2 col-sm-2" style="text-align:center">
                            标题
                        </div>
                        <div class="col-xs-1 col-sm-1" style="text-align:center">
                            讲课专家
                        </div>
                        <div class="col-xs-1 col-sm-1" style="text-align:center">
                            状态
                        </div>
                        <div class="col-xs-1 col-sm-1" style="text-align:center">
                            发送
                        </div>
                        <div class="col-xs-1 col-sm-1" style="text-align:center">
                            关注人数
                        </div>
                        <div class="col-xs-1 col-sm-1" style="text-align:center">
                            开始时间
                        </div>
                        <div class="col-xs-1 col-sm-1" style="text-align:center">
                            结束时间
                        </div>
                        <div class="col-xs-3 col-sm-3" style="text-align:center">
                            操作
                        </div>
                    </div>
                </div>
            </div>
            <?php $i=1; foreach($r显示2['result'] as $v){?>
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="row" >

                            <div class="col-xs-1 col-sm-1" style="text-align:center">
                                <?= $v['theme']?><span style="color: red;"><?php if($v['is_test']==1) echo '(测试数据)';   ?></span>
                            </div>
                            <div class="col-xs-2 col-sm-2" style="text-align:center">
                                <a href="<?= $v['视频url']?>"><?= $v['title']?></a>
                            </div>
                            <div class="col-xs-1 col-sm-1" style="text-align:center">
                                <?=$v['name']?>&nbsp;
                            </div>
                            <div class="col-xs-1 col-sm-1" style="text-align:center">
                                <?=$v['状态']?>&nbsp;
                            </div>
                            <div class="col-xs-1 col-sm-1" style="text-align:center">
                                <?=$v['发送']?>&nbsp;
                            </div>
                            <div class="col-xs-1 col-sm-1" style="text-align:center">
                                <?=$v['数量']?>&nbsp;
                            </div>
                            <div class="col-xs-1 col-sm-1" style="text-align:center">
                                <?=$v['开始时间']?>
                            </div>
                            <div class="col-xs-1 col-sm-1" style="text-align:center">
                                <?=$v['结束时间']?>
                            </div>
                            <div class="col-xs-3 col-sm-3" style="text-align:center">
                                <?php
                                   // if($v['状态'] =='预备' && date("Y-m-d H:i:s",(strtotime($v['开始时间']) - 3600)) > date("Y-m-d H:i:s")) echo '<a class="btn btn-primary btn-xs" href="back.php?state=back8Shipin_Lessons&id='.$v['id'].'">编辑</a>';?>
                                <button onclick="ceshi('<?=$v['id']?>')" class="btn btn-primary btn-xs">测试</button>
                                <a class="btn btn-primary btn-xs" href="../back.php?state=back8Shipin_Lessons&id=<?= $v['id']?>">编辑</a>
                                <a href="../back.php?state=back8Focus_Show&id=<?=$v['id']?>&title=<?= $v['title']?>&num=<?= $v['数量']?>"  class="btn btn-primary btn-xs">查看</a></b>

                                <button onclick="disabled=true;tuisong('<?=$v['id']?>')" class="btn btn-primary btn-xs">推送</button>
                                <button onclick="disabled=true;keQian_tuisong('<?=$v['id']?>')" class="btn btn-primary btn-xs">课前推送</button>
                                <button onclick="disabled=true;tuisong2('<?=$v['id']?>')" class="btn btn-primary btn-xs">未成功重发</button>
                                <?php
                                //视频开始一个小时后， 视频结束后才能编辑内容
                                if($v['状态'] =='预备'){?>
                                <button onclick="f修改课程状态('开始',<?=$v['id']?>)" class="btn btn-primary btn-xs">开始上课</button>
                                <?php }?>
                                <?php
                                //视频开始一个小时后， 视频结束后才能编辑内容
                                if($v['状态'] =='开始'){?>
                                    <button onclick="f修改课程状态('结束',<?=$v['id']?>)" class="btn btn-primary btn-xs">结束上课</button>
                                <?php }?>
                            </div>

                        </div>
                    </div>
                </div>
                <?php  $i++;}?>
        </div>
        <?php  echo $r显示2['show'];?>
    </div>


</div>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../resource/js/jquery-1.11.1.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../resource/js/bootstrap.min.js"></script>
<script language="JavaScript">
    function ceshi(id){
        var oid=$("#oid").val();
        if(oid){
            $.post('BackSellerAjax.php',{'id':id,'oid':oid,'businessFlag':'推送课程'},function(data){

                alert("测试通过");
                location.reload();
            });
        }else{
            alert('请填写oid');
        }

    }

    function tuisong(id){
        var res = confirm('您真的确定吗?');
        if(res) {
            var oid = $("#oid").val();
            $.post('BackSellerAjax.php', {'id': id, 'oid': oid, 'businessFlag': '推送课程'}, function (data) {

                alert("推送成功");
                location.reload();
            });
        }
    }

    function keQian_tuisong(id){
        var res = confirm('您真的确定吗?');
        if(res) {
            var oid = $("#oid").val();
            $.post('BackSellerAjax.php', {'id': id, 'oid': oid, 'businessFlag': '课前推送课程'}, function (data) {

                alert("推送成功");
                location.reload();
            });
        }
    }

    function tuisong2(id){
        var res = confirm('您真的确定吗?');
        if(res) {
            var oid = null;
            $.post('BackSellerAjax.php', {'id': id, 'businessFlag': '推送未成功课程'}, function (data) {

                alert("推送成功");
                location.reload();
            });
        }
    }
    function f修改课程状态(状态,id){
        $.post('agent_manages.php',{'课程id':id,"状态":状态,'参数':'修改课程状态'},function(data){

            if(data){
                alert(状态+"课程成功!");
                location.replace(location.href);
            }else {
                alert(状态+"课程失败!");
            }
        });
    }
</script>
</body>
</html>